import java.util.*
import java.io.*
enum class Yi(val id: Int, val tag: String) {
    YIN(0, "阴"),  YOG(1, "阳");
    fun getIndex(): Int = id; fun getName(): String = tag;
    fun getByIndex(idx: Int): Yi? = when(idx % 2) {
        0 -> Yi.YIN
        1 -> Yi.YOG
        else -> null
    }
}
enum class Wx(val id: Int, val tag: String) {
    MUU(1, "木"), HUO(2, "火"), TUU(3, "土"), JIN(4, "金"), SHV(5, "水");
    fun getIndex(): Int = id; fun getName(): String = tag
}
enum class Gan(val id: Int, val tag: String, val y: Yi, val x: Wx) {
    JIA(1, "甲", Yi.YOG, Wx.MUU), YII( 2, "乙", Yi.YIN, Wx.MUU),
    BIN(3, "丙", Yi.YOG, Wx.HUO), DIN( 4, "丁", Yi.YIN, Wx.HUO),
    WUU(5, "戊", Yi.YOG, Wx.TUU), JII( 6, "己", Yi.YIN, Wx.TUU),
    GEN(7, "庚", Yi.YOG, Wx.JIN), XIN( 8, "辛", Yi.YIN, Wx.JIN),
    REN(9, "壬", Yi.YOG, Wx.SHV), GUI(10, "癸", Yi.YIN, Wx.SHV);
    fun getIndex(): Int = id; fun getName(): String = tag
    fun getYi(): Yi = y; fun getWx(): Wx = x
}
enum class Zhi(val id: Int, val tag: String, val y: Yi, val x: Wx) {
    ZII( 1, "子", Yi.YOG, Wx.SHV), CHO( 2, "丑", Yi.YIN, Wx.TUU),
    YIN( 3, "寅", Yi.YOG, Wx.MUU), MAO( 4, "卯", Yi.YIN, Wx.MUU),
    CHN( 5, "辰", Yi.YOG, Wx.TUU), SII( 6, "巳", Yi.YIN, Wx.HUO),
    WUU( 7, "午", Yi.YOG, Wx.HUO), WEI( 8, "未", Yi.YIN, Wx.TUU),
    SHN( 9, "申", Yi.YOG, Wx.JIN), YOU(10, "酉", Yi.YIN, Wx.JIN),
    XUU(11, "戌", Yi.YOG, Wx.TUU), HAI(12, "亥", Yi.YIN, Wx.SHV);
    fun getIndex(): Int = id; fun getName(): String = tag;
    fun getYi(): Yi = y; fun getWx(): Wx = x;
}
enum class HuaJia(val id: Int, val g: Gan, val z: Zhi, val ny: String) {
    JIA_ZII( 1, Gan.JIA, Zhi.ZII, "海中金"), YII_CHO( 2, Gan.YII, Zhi.CHO, "海中金"),
    BIN_YIN( 3, Gan.BIN, Zhi.YIN, "炉中火"), DIN_MAO( 4, Gan.DIN, Zhi.MAO, "炉中火"),
    WUU_CHN( 5, Gan.WUU, Zhi.CHN, "大林木"), JII_SII( 6, Gan.JII, Zhi.SII, "大林木"),
    GEN_WUU( 7, Gan.GEN, Zhi.WUU, "路旁土"), XIN_WEI( 8, Gan.XIN, Zhi.WEI, "路旁土"),
    REN_SHN( 9, Gan.REN, Zhi.SHN, "剑锋金"), GUI_YOU(10, Gan.GUI, Zhi.YOU, "剑锋金"),
    JIA_XUU(11, Gan.JIA, Zhi.XUU, "山头火"), YII_HAI(12, Gan.YII, Zhi.HAI, "山头火"),
    BIN_ZII(13, Gan.BIN, Zhi.ZII, "涧下水"), DIN_CHO(14, Gan.DIN, Zhi.CHO, "涧下水"),
    WUU_YIN(15, Gan.WUU, Zhi.YIN, "城墙土"), JII_MAO(16, Gan.JII, Zhi.MAO, "城墙土"),
    GEN_CHN(17, Gan.GEN, Zhi.CHN, "白腊金"), XIN_SII(18, Gan.XIN, Zhi.SII, "白腊金"),
    REN_WUU(19, Gan.REN, Zhi.WUU, "杨柳木"), GUI_WEI(20, Gan.GUI, Zhi.WEI, "杨柳木"),
    JIA_SHN(21, Gan.JIA, Zhi.SHN, "泉中水"), YII_YOU(22, Gan.YII, Zhi.YOU, "泉中水"),
    BIN_XUU(23, Gan.BIN, Zhi.XUU, "屋上土"), DIN_HAI(24, Gan.DIN, Zhi.HAI, "屋上土"),
    WUU_ZII(25, Gan.WUU, Zhi.ZII, "霹雳火"), JII_CHO(26, Gan.JII, Zhi.CHO, "霹雳火"),
    GEN_YIN(27, Gan.GEN, Zhi.YIN, "松柏木"), XIN_MAO(28, Gan.XIN, Zhi.MAO, "松柏木"),
    REN_CHN(29, Gan.REN, Zhi.CHN, "常流水"), GUI_SII(30, Gan.GUI, Zhi.SII, "常流水"),
    JIA_WUU(31, Gan.JIA, Zhi.WUU, "沙中金"), YII_WEI(32, Gan.YII, Zhi.WEI, "沙中金"),
    BIN_SHN(33, Gan.BIN, Zhi.SHN, "山下火"), DIN_YOU(34, Gan.DIN, Zhi.YOU, "山下火"),
    WUU_XUU(35, Gan.WUU, Zhi.XUU, "平地木"), JII_HAI(36, Gan.JII, Zhi.HAI, "平地木"),
    GEN_ZII(37, Gan.GEN, Zhi.ZII, "壁上土"), XIN_CHO(38, Gan.XIN, Zhi.CHO, "壁上土"),
    REN_YIN(39, Gan.REN, Zhi.YIN, "金箔金"), GUI_MAO(40, Gan.GUI, Zhi.MAO, "金箔金"),
    JIA_CHN(41, Gan.JIA, Zhi.CHN, "佛灯火"), YII_SII(42, Gan.YII, Zhi.SII, "佛灯火"),
    BIN_WUU(43, Gan.BIN, Zhi.WUU, "天河水"), DIN_WEI(44, Gan.DIN, Zhi.WEI, "天河水"),
    WUU_SHN(45, Gan.WUU, Zhi.SHN, "大驿土"), JII_YOU(46, Gan.JII, Zhi.YOU, "大驿土"),
    GEN_XUU(47, Gan.GEN, Zhi.XUU, "钗钏金"), XIN_HAI(48, Gan.XIN, Zhi.HAI, "钗钏金"),
    REN_ZII(49, Gan.REN, Zhi.ZII, "桑柘木"), GUI_CHO(50, Gan.GUI, Zhi.CHO, "桑柘木"),
    JIA_YIN(51, Gan.JIA, Zhi.YIN, "大溪水"), YII_MAO(52, Gan.YII, Zhi.MAO, "大溪水"),
    BIN_CHN(53, Gan.BIN, Zhi.CHN, "沙中土"), DIN_SII(54, Gan.DIN, Zhi.SII, "沙中土"),
    WUU_WUU(55, Gan.WUU, Zhi.WUU, "天上火"), JII_WEI(56, Gan.JII, Zhi.WEI, "天上火"),
    GEN_SHN(57, Gan.GEN, Zhi.SHN, "石榴木"), XIN_YOU(58, Gan.XIN, Zhi.YOU, "石榴木"),
    REN_XUU(59, Gan.REN, Zhi.XUU, "大海水"), GUI_HAI(60, Gan.GUI, Zhi.HAI, "大海水");
    fun getIndex(): Int = id
    fun getName(): String = g.getName() + z.getName()
    fun getGan(): Gan = g
    fun getZhi(): Zhi = z
    fun getNaYinName(): String = ny
    fun getNaYinWx(): Wx = when(ny[2]) {
        '木' -> Wx.MUU; '火' -> Wx.HUO; '土' -> Wx.TUU; '金' -> Wx.JIN; else -> Wx.SHV;
    }
}
enum class Ju(val riChen: HuaJia, val ganShangChen: Zhi) {
    甲子_寅(HuaJia.JIA_ZII, Zhi.YIN) {
        override fun getA() = """
甲子日第一局　干上寅
　　课体：伏吟，元胎。
　　课义：两贵差跌，六虎陈列，病讼皆畏，仕宦怡悦。
　　解曰：昼贵临于夜地，夜贵临于昼地，谓之贵人差跌。干贵者，事多参差，不能归一。干支拱定昼贵，止求一处贵人方为有益。四课上两寅属虎，二子乘虎，初传寅虎，末传申虎，所谓六虎陈列也。二虎临宅，申虎又属官鬼，常人占病、占讼，岂不可畏？德禄驿马临日发用，末传官鬼乘虎为催官使者，故仕宦占之则怡悦也。甲上加寅或卯，名懒求财格，心多退悔。
　　断曰：此自任之卦，又曰元胎，利静不利动，利上不利下，利君子不利小人。刑中有害，破中有合，吉凶祸福，相为倚伏。
　　天时：水火伏匿，龙神入庙，无雨有风。谋望：先难后易。家宅：恐有动迁，夜占防孝服。婚姻：不利，昼占女子美好；夜占女子丑恶。疾病：主失音，肝家受病，肾水枯竭，宜清金滋水。胎孕：聋哑。求财：不甚得意，防人暗害。捕获：女人在西北，男人在正南，俱不出境。遗失：在家中。行人：远者回转，近者将至。出行：宜从旱路。征伐：玉帐经云，青龙发用，得宝货与图书，防有伏兵，亦防吉中有凶。
　　毕法云：虎临干鬼凶速速，日乘旺禄休狂妄，虎乘遁鬼殃非浅，宾主不投刑在上。吴越春秋，三月酉时范蠡占吴王病，三传寅巳申，德禄在寅，病在巳，绝在申，春木旺金囚，无伤也。己巳有瘳，壬申全愈。
"""
    }
    ;
    abstract fun getA(): String;
}

fun main() {
    val file1 = File("data.txt")
    val file2 = File("data.js")
    val bufferedReader = file1.bufferedReader(Charsets.UTF_8, DEFAULT_BUFFER_SIZE)
    val writer = file2.writer(Charsets.UTF_8)
    var line: String

    try {
        while (true) {
            line = bufferedReader.readLine() ?: break;
            var duan = "断镜云: ";
            if(line.indexOf(duan) > 0) {
                var lines = line.split(duan)
                if(lines.size == 2) {
                    println(lines.get(0) + "\n" + duan + lines.get(1) + "\n")
                    writer.write(lines.get(0) + "\n" + duan + lines.get(1) + "\n");
                }else {
                    println(line)
                    writer.write(line.trim() + "\n");
                }
            }else {
                println(line)
                writer.write(line.trim() + "\n");
            }
        }
    } catch (e: Exception) {
        e.printStackTrace()
    } finally {
        try {
            bufferedReader.close()
            writer.close();
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
    // println(Ju.JIA_ZII_YIN.getA());
    // println(Ju.甲子_寅.getA());
    // val s1: String
    // val s2: String
    // val sc = Scanner(System.`in`)
    // print("请输入第一个字符串：")
    // s1 = sc.nextLine()
    // print("请输入第二个字符串：")
    // s2 = sc.next()
    // println("输入的字符串是：$s1.$s2")
}